import Vue from 'vue'
import VueRouter from 'vue-router'
import login from '../views/login.vue'
import Home from '../views/Home.vue'
import Welcome from '../views/Welcome.vue'
import Users from '../views/users/index.vue'
import Rights from '../views/power/rights.vue'
import Roles from '../views/power/Roles.vue'
import goodsCate from '../views/goods/cate.vue'
import goodsParams from '../views/goods/params.vue'
import List from '../views/goods/list.vue'
import Addlist from '../views/goods/addlist.vue'
import VueQuillEditor from 'vue-quill-editor'
import Order from '../views/Order.vue'
import reports from '../views/reports.vue'
import 'quill/dist/quill.core.css' // import styles
import 'quill/dist/quill.snow.css' // for snow theme
import 'quill/dist/quill.bubble.css' // for bubble theme
Vue.use(VueQuillEditor)
Vue.use(VueRouter)
const routes = [
  { path: '/', redirect: '/login' },
  { path: '/login', component: login },
  {
    path: '/home',
    component: Home,
    redirect: '/welcome',
    children: [
      { path: '/welcome', component: Welcome },
      { path: '/users', component: Users },
      { path: '/rights', component: Rights },
      { path: '/roles', component: Roles },
      { path: '/categories', component: goodsCate },
      { path: '/params', component: goodsParams },
      { path: '/goods', component: List },
      { path: '/add/goods', component: Addlist },
      { path: '/orders', component: Order },
      { path: '/reports', component: reports }
    ]
  }
]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  const token = sessionStorage.getItem('token')
  if (token) {
    next()
  } else {
    if (to.path === '/login') return next()
    next('/login')
  }
})
export default router
